package bb.lanxing.util.text;

import android.content.Context;
import android.os.Looper;
import android.widget.Toast;
import bb.lanxing.lib.base.BaseApplication;

public class ToastHelper {
    public static void toast(Context context, final int textRes) {
        toast(context, BaseApplication.get().getText(textRes), 0);
    }

    public static void toastLong(Context context, final int textRes) {
        toast(context, BaseApplication.get().getText(textRes), 1);
    }

    public static void toast(Context context, final CharSequence text) {
        toast(context, text, 0);
    }

    public static void toastLong(Context context, final CharSequence text) {
        toast(context, text, 1);
    }

    private static void toast(final Context context, final CharSequence text, final int duration) {
        if (Looper.myLooper() == Looper.getMainLooper()) {
            Toast.makeText(context, text, duration).show();
        } else {
            BaseApplication.get().getHandler().post(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(context, text, duration).show();
                }
            });
        }
    }
}
